package com.vca.common.request;

import cn.hutool.core.util.ObjectUtil;
import com.vca.common.exception.VcaException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author chenbing
 * @date 2022/11/9   17:45
 */
@Data
public class PreOrderCommonRequest {

    @ApiModelProperty(value = "预下单类型（“shoppingCart”：购物车下单，“buyNow”：立即购买，”again“： 再次购买")
    @NotBlank(message = "预下单类型不能为空")
    private String preOrderType;

    @ApiModelProperty(value = "订单类型 0 = 课程 1= 套课 2=讲座 3=展览 4=商品")
    private Integer type;

    @ApiModelProperty(value = "课程/套课/讲座/展览预下单详情")
    private PreOrderDetailRequestVo preOrderDetail;

    @ApiModelProperty(value = "商品订单详情列表")
    private List<PreOrderDetailRequest> orderDetails;

    @Data
    public static class PreOrderDetailRequestVo {
        @ApiModelProperty(value = "课程/套课/讲座/展览ID")
        @NotNull(message = "课程ID不能为空")
        private Long mainId;

        public Long getMainId() {
            if (ObjectUtil.isNull(mainId)) {
                throw new VcaException("课程ID不能为空");
            }
            return mainId;
        }

        @ApiModelProperty(value = "排期List")
        private List<ScheduleLing> scheduleLings;

        public List<ScheduleLing> getScheduleLings() {
            if (ObjectUtil.isNull(scheduleLings)) {
                throw new VcaException("排期不能为空");
            }
            if (scheduleLings.size() <= 0) {
                throw new VcaException("排期不能为空");
            }
            return scheduleLings;
        }

        @Data
        public static class ScheduleLing {
            @NotNull(message = "课程ID不能为空")
            private Long courseId;
            @NotNull(message = "排期ID不能为空")
            private Long scheduleId;

            public Long getCourseId() {
                if (ObjectUtil.isNull(courseId)) {
                    throw new VcaException("课程ID不能为空");
                }
                return courseId;
            }

            public Long getScheduleId() {
                if (ObjectUtil.isNull(scheduleId)) {
                    throw new VcaException("排期ID不能为空，请选择排期");
                }
                return scheduleId;
            }
        }

        @ApiModelProperty(value = "商品数量")
        private Integer count;
    }

    @Data
    public static class PreOrderDetailRequest {
        @ApiModelProperty(value = "购物车编号，购物车预下单时必填")
        private Long shoppingCartId;

        @ApiModelProperty(value = "商品的主键ID")
        @NotBlank(message = "商品的主键ID不能为空")
        private Integer productId;

        @ApiModelProperty(value = "商品规格属性id（立即购买、活动购买必填）")
        private Integer attrValueId;

        @ApiModelProperty(value = "商品数量")
        private Integer count = 1;
    }


}
